import React, { Component } from 'react'

export default class TodoInput extends Component {
  state = {
    todo: ''
  }
  setTodo = (e) => {
    this.setState({
      todo: e.target.value
    })
  }
  submitTodo = (e) => {
    console.log(e)
    if(e.keyCode === 13) {
      this.props.addTodo(this.state.todo)

      this.setState({
        todo: ''
      })
    }
  }
  render() {
    const {todo} = this.state
    return (
      <div className='todo-input'>
        <input type="text" value={todo} onChange={this.setTodo} onKeyDown={this.submitTodo} />
      </div>
    )
  }
}
